#pragma once

#include "../Utility/Utility.h"
#include "../Container/SLList.h"
#include "../Container/Dictionary.h"

#include "IObject.h"

class ObjectManager
{
	typedef Dictionary<unsigned long, void*> ObjectRegisterMap;

	typedef SLList<IObject*> ObjectList;

	ObjectRegisterMap registeredObjects;

	ObjectList currentObjects;

public:

	ObjectManager(void) : registeredObjects(Utility::HashFuncULong) { }
	~ObjectManager(void) { }

	template<typename T>
	void RegisterObject(const HashString& objectID)
	{
		registeredObjects.Insert(objectID.GetIdentity(), new StackFactory<T>);
	}

	template<typename T>
	T* GetNewObject(const HashString& objectID)
	{
		return ((StackFactory<T>*)registeredObjects[objectID.GetIdentity()])->NewObject();
	}

	////////////////////////////////////////////////////////////////////////////////////////////////////
	/// <Summary>	Initializes the object manager </Summary>
	////////////////////////////////////////////////////////////////////////////////////////////////////
	void Initialize();

	////////////////////////////////////////////////////////////////////////////////////////////////////
	/// <Summary>	Shuts down the object manager </Summary>
	////////////////////////////////////////////////////////////////////////////////////////////////////
	void Shutdown();

	void AddObject(IObject* obj);

	void RemoveObject(IObject* obj);

	void RemoveObject(const char* name);

	IObject* FindObject(const char* name);

	void Update(float delta);

	void DeleteObject(IObject* obj);

	void ClearObjects();
};